<template>
  <div id="app">
    <nav>
      <!-- 通过全局组件实现路由跳转 -->
      <!-- <router-link to="/home" tag="button" replace>首页</router-link>
      <router-link to="/about" tag="button" replace>关于</router-link> -->
      <!-- <router-link :to="'/profile/' + userId" tag="button" replace>我的</router-link> -->
      <!-- <router-link v-bind:to="'/profile/' + userId" tag="button" replace>我的</router-link> -->

      <!-- query -->
      <!-- <router-link v-bind:to="{path:'/profile/'+ userId, query:{name:'翔哥', sex:'不详', age:99, height:1.99}}" tag="button" replace>我的</router-link> -->
      <!-- query代码方式 -->
      <button @click="homeClick">首页</button>
      <button @click="aboutClick">关于</button>
      <button @click="profileClick">我的</button>
      <button @click="shopClick">购物车</button>

      <!--通过代码的方式实现路由跳转 -->
      <!-- <button @click="homeClick">首页</button>
      <button @click="aboutClick">关于</button>
      <button @click="profileClick">我的</button>
      <button @click="shopClick">购物车</button> -->
    </nav>

    <keep-alive>
      <router-view/>
    </keep-alive>
  </div>
</template>

<script>
export default {
  name: 'App',
  data(){
    return{
      userId : "kfc"
    }
  },
  methods:{
    profileClick(){
      this.$router.replace({
        path:'/profile/' + this.userId,query:{
          name:'翔哥', 
          sex:'不详', 
          age:99,
          height:1.99
        }
      }).catch(err => err);
    },
    homeClick(){
      this.$router.replace('/home').catch(err => err);
    },
    aboutClick(){
      this.$router.replace('/about').catch(err => err);
    },
    shopClick(){
      this.$router.replace('/shopping').catch(err => err);
    }
  }
  // methods:{
  //   homeClick(){
  //     // console.log('homeClick');
  //     // location.hash = '/home';
  //     // history.pushState({}, '', '/home');不能用这个 只能用this.$router.push();
  //     //history.replaceState({}, '', '/about')  替换一条历史记录,不能通过前进后退按钮找到以前的历史记录
  //     // 路由跳转,经过vuerouter
  //     // this.$router.push('/home');
  //     this.$router.replace('/home');
  //   },
  //   aboutClick(){
  //     // console.log('aboutClick');
  //     // location.hash = '/about';
  //     // history.pushState({}, '', '/about');
  //     // this.$router.push('/about');
  //     this.$router.replace('/about');
  //   },
  //   profileClick(){
  //     // console.log('profileClick');
  //     // location.hash = '/profile';
  //     // history.pushState({}, '', '/profile');
  //     // this.$router.push('/profile');
  //     this.$router.replace('/about');
  //   },
  //   shopClick(){
  //     this.$router.replace('/shopping');
  //   }
  // }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.show{
  background-color: rgb(253, 117, 219);
}
</style>
